package com.boxedinsoftware.betamax.dial;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.Toast;

public class AccountManager extends Activity
{
	
	protected static final String[] PROVIDERS = {"none" , "12voip.com","actionvoip.com", "budgetsip.com",
		   "calleasy.com", "callingcredit.com" , "cheapvoip.com","dialcheap.com" , "dialnow.com", "freecall.com", "internetcalls.com",
		   "intervoip.com", "jumblo.com", "justvoip.com", "lowratevoip.com","megavoip.com" , "netappel.fr", "nonoh.net",
		   "poivy.com", "powervoip.com", "rynga.com", "sipdiscount.com", "smartvoip.com", "smsdiscount.com",
		   "smslisto.com", "sparvoip.de", "voipblast.com" , "voipbuster.com", "voipbusterpro.com", "voipcheap.co.uk",
		   "voipcheap.com", "voipdiscount.com", "voipgain.com", "voipian.com", "voipraider.com",
		   "voipstunt.com", "voipwise.com", "voipzoom.com", "webcalldirect.com" };
	
	AccountsSQLHelper dh;
	ArrayList<SearchResults> searchResults;
	ListView lv1;
	
		@Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.acc_view);
	        this.dh = new AccountsSQLHelper(AccountManager.this.getApplicationContext());
	        searchResults = refresh();
	        
	        lv1 = (ListView) findViewById(R.id.list);
	        lv1.setAdapter(new AccountsBaseAdapter(this, searchResults));
	        registerForContextMenu(lv1);
	        
	        lv1.setOnItemClickListener(new OnItemClickListener() {
	         public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
	          Object o = lv1.getItemAtPosition(position);
	          SearchResults fullObject = (SearchResults)o;
	          Toast.makeText(AccountManager.this, "Refreshing balance for " + fullObject.getProvider() +" . Please wait ...", Toast.LENGTH_SHORT).show();
			  refreshBalance(fullObject.getID());
	         }  
	        });
	        
	        /*lv1.setOnItemLongClickListener(new OnItemLongClickListener() {
		         public boolean onItemLongClick(AdapterView<?> a, View v, int position, long id) { 
		          Object o = lv1.getItemAtPosition(position);
		          final SearchResults fullObject = (SearchResults)o;
		          AlertDialog.Builder builder = new AlertDialog.Builder(AccountManager.this);
		          builder.setMessage("Are you sure you want to delete " + fullObject.getProvider() + " account from Betamax Dialer Pro ?")
		                 .setCancelable(false)
		                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		                     public void onClick(DialogInterface dialog, int id) {
		                          AccountManager.this.dh.deleteRow(fullObject.getID());
		                          searchResults = refresh();
		      					  lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));
		                     }
		                 })
		                 .setNegativeButton("No", new DialogInterface.OnClickListener() {
		                     public void onClick(DialogInterface dialog, int id) {
		                          dialog.cancel();
		                     }
		                 });
		          AlertDialog alert = builder.create();
		          alert.show();
		          return true;
		         }  
		        });*/
	        
	        
	        
	        
	        
	        
	        Button new_account = (Button)findViewById(R.id.new_course_button);
	        
	        new_account.setOnClickListener(new OnClickListener(){

				public void onClick(View v) {
					
					//courseChooser customizeDialog = new courseChooser(AccountManager.this);
					//customizeDialog.show();
					
					//Toast.makeText(AccountManager.this, "Add Account clicked", Toast.LENGTH_SHORT).show();
					//AccountManager.this.dh.deleteAll();
					//AccountManager.this.dh.insert("12voip.com","amokk","butthead","6476806419" , 0.0);
					//AccountManager.this.dh.insert("dialnow.com","vasile","ion","12342356", 0.0);
					//AccountManager.this.dh.insert("internetcalls.com","ionescu","vasile","2145325", 0.0);
					
					AlertDialog.Builder builder;
					

					Context mContext = AccountManager.this;
					LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
					View layout = inflater.inflate(R.layout.add_account,
					                               (ViewGroup) findViewById(R.id.layout_root));

					final Spinner providerSelector = (Spinner)layout.findViewById(R.id.searchCriteria);
					final EditText username = (EditText)layout.findViewById(R.id.acc_username);
					final EditText password = (EditText)layout.findViewById(R.id.acc_password);
					final EditText accnumber = (EditText)layout.findViewById(R.id.acc_number_edittext);
					Button get_acc_number = (Button)layout.findViewById(R.id.button2);
					Button add_acc = (Button)layout.findViewById(R.id.add_account);
					
					get_acc_number.setOnClickListener(new OnClickListener(){

						public void onClick(View arg0) {
						String url = null;
						int providerInt = providerSelector.getSelectedItemPosition();
						
						if(providerInt == 0)
							url = null;
						if(providerInt == 1)
						url = "http://www.12voip.com/en/geo.html";	
						if(providerInt == 2)
						url = "http://www.actionvoip.com/en/geo.html";
						if(providerInt == 3)
						url = null;
						if(providerInt == 4)
						url = "http://www.calleasy.com/en/accessnumbers.html";
						if(providerInt == 5)
						url = "http://www.callingcredit.com/en/instructions.html";
						if(providerInt == 6)
						url = "http://www.cheapvoip.com/en/geo.html";
						if(providerInt == 7)
							url = "http://www.dialcheap.com/en/accessnumbers.html";
						if(providerInt == 8)
						url = "http://www.dialnow.com/en/accessnumbers.html";
						if(providerInt == 9)
						url = "http://www.freecall.com/en/geo.html";	
						if(providerInt == 10)
						url = "http://www.internetcalls.com/en/geo.html";
						if(providerInt == 11)
						url = "http://www.intervoip.com/en/geo.html";
						if(providerInt == 12)
					    url = "http://www.jumblo.com/en/geo.html";
						if(providerInt == 13)
							url = "http://www.justvoip.com/en/geo.html";
						if(providerInt == 14)
							url = "http://www.lowratevoip.com/en/geo.html";
						if(providerInt == 15)
							url = "http://www.megavoip.com/fr/geo.html";
						if(providerInt == 16)
							url = "http://www.netappel.fr/fr/geo.html";
						if(providerInt == 17)
							url = "http://www.nonoh.net/en/geo.html";
						if(providerInt == 18)
							url = "http://www.poivy.com/en/geo.html";
						if(providerInt == 19)
							url = "http://www.powervoip.com/en/geo.html";
						if(providerInt == 20)
							url = "http://www.rynga.com/en/geo.html";
						if(providerInt == 21)
							url = "http://www.sipdiscount.com/en/geo.html";
						if(providerInt == 22)
							url = "http://www.smartvoip.com/en/geo.html";
						if(providerInt == 23)
							url = "http://www.smsdiscount.com/en/geo.html";
						if(providerInt == 24)
							url = "http://www.smslisto.com/en/geo.html";
						if(providerInt == 25)
							url = "http://www.sparvoip.de/de/geo.html";
						if(providerInt == 26)
							url = "http://www.voipblast.com/en/geo.html";
						if(providerInt == 27)
							url = "http://www.voipbuster.com/en/geo.html";
						if(providerInt == 28)
							url = "http://www.voipbusterpro.com/en/geo.html";
						if(providerInt == 29)
							url = "http://www.voipcheap.co.uk/en/geo.html";
						if(providerInt == 30)
							url = "http://www.voipcheap.com/en/geo.html";
						if(providerInt == 31)
							url = "http://www.voipdiscount.com/en/geo.html";
						if(providerInt == 32)
							url = "http://www.voipgain.com/en/geo.html";
						if(providerInt == 33)
							url = null;
						if(providerInt == 34)
							url = "http://www.voipraider.com/en/geo.html";
						if(providerInt == 35)
							url = "http://www.voipstunt.com/en/geo.html";
						if(providerInt == 36)
							url = "http://www.voipwise.com/en/geo.html";
						if(providerInt == 37)
							url = null;
						if(providerInt == 38)
							url = "http://www.webcalldirect.com/en/geo.html";
						
						
							
						
						
						if(url == null)
						{
							Toast.makeText(getApplicationContext(), "Please choose a provider first.", Toast.LENGTH_LONG).show();
						}
						else
						{
						Intent i = new Intent(Intent.ACTION_VIEW);
						i.setData(Uri.parse(url));
						startActivity(i);
						}
						
					}
							
						
						
						
					});
					
					
					

					builder = new AlertDialog.Builder(mContext);
					builder.setView(layout);
					final AlertDialog alertDialog = builder.create();
					alertDialog.show();
					
					//searchResults = refresh();
					//lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));

					add_acc.setOnClickListener(new OnClickListener(){

						public void onClick(View arg0) {
							int error = 0;
							int providerInt = providerSelector.getSelectedItemPosition();
							String provider_string = PROVIDERS[providerInt];
							
							String username_string = username.getText().toString().trim();
							
							String password_string = password.getText().toString().trim();
							
							String acc_number_string = accnumber.getText().toString().trim();
							
							if(provider_string.equalsIgnoreCase("none")){
								Toast.makeText(getApplicationContext(), "Please choose a provider first.", Toast.LENGTH_LONG).show();
								error = 1;
							}
							else if((provider_string.equalsIgnoreCase("dialcheap.com") || provider_string.equalsIgnoreCase("megavoip.com") || provider_string.equalsIgnoreCase("voipian.com")) && acc_number_string.equalsIgnoreCase("")){
								Toast.makeText(getApplicationContext(), "The selected provider is not yet supported by Callback", Toast.LENGTH_LONG).show();
								error = 1;
							}
							else if(username_string.equalsIgnoreCase("")){
								Toast.makeText(getApplicationContext(), "Please fill up the username field", Toast.LENGTH_LONG).show();
								error = 1;
							}
							else if(password_string.equalsIgnoreCase("")){
								Toast.makeText(getApplicationContext(), "Please fill_up the passworld field", Toast.LENGTH_LONG).show();
								error = 1;
							}
							else if(acc_number_string.equalsIgnoreCase("")){
								Toast.makeText(getApplicationContext(), "No Access Number provided. You will only be able to Callback from this account.", Toast.LENGTH_LONG).show();
							}
							
							if(error == 1)
								error = 0;
							else
							{
								Toast.makeText(getApplicationContext(), "Fetching account data. Please wait...", Toast.LENGTH_LONG).show();
								String[] params = {provider_string , username_string, password_string, acc_number_string , ""};
								//Toast.makeText(getApplicationContext(), params[0] + "," + params[1] + "," + params[2] + "," + params[3], Toast.LENGTH_LONG).show();
								new add_account().execute(params);
								alertDialog.cancel();
								
								
								
							}
								
						}
						
						
						
						
					});
					
				}
	        	
	        	
	        	
	        	
	        });
	        
	        
	        Button refresh = (Button)findViewById(R.id.refresh_button);
	        
	        refresh.setOnClickListener(new OnClickListener(){

				public void onClick(View v) {
					
					//courseChooser customizeDialog = new courseChooser(AccountManager.this);
					//customizeDialog.show();
					
					Toast.makeText(AccountManager.this, "Refreshing balance for all accounts. Please wait ...", Toast.LENGTH_SHORT).show();
					refreshBalance();
						
					
					
				}
	        	
	        	
	        	
	        	
	        });
	        
	      
	      
	      
	      

	  	  
	        
		}
		
		
		
		private ArrayList<SearchResults> refresh(){
		     ArrayList<SearchResults> results = new ArrayList<SearchResults>();
		     
		     SearchResults sr1;
		     Cursor cursor = this.dh.selectAll();
		        while (cursor.moveToNext()) {
		        	sr1 = new SearchResults();
		            sr1.setID(cursor.getInt(0));
		            sr1.setProvider(cursor.getString(1));
		            sr1.setUsername(cursor.getString(2));
		            sr1.setAccNumber(cursor.getString(3));
		            sr1.setBalance(cursor.getDouble(4));
		            results.add(sr1);
		          }
		         
		     return results;
		    }
		
		public void refreshBalance(){
		     
		     Cursor cursor = this.dh.selectAllForBalance();
		        while (cursor.moveToNext()) {
		            int ID = cursor.getInt(0);
		            String provider = cursor.getString(1);
		            String username = cursor.getString(2);
		            String password = cursor.getString(3);
		            String[] params = {"" + ID , provider, username, password , ""};
		            new refresh_balance().execute(params);
		          }

		    }
		
		private void refreshBalance(int row_id){
		     
		     Cursor cursor = this.dh.selectAllForBalance();
		        while (cursor.moveToNext()) {
		            int ID = cursor.getInt(0);
		            String provider = cursor.getString(1);
		            String username = cursor.getString(2);
		            String password = cursor.getString(3);
		            String[] params = {"" + ID , provider, username, password , ""};
		            if(ID == row_id)
		            	new refresh_balance().execute(params);
		          }
		         
		     
		    }
		
	
		 public class add_account extends AsyncTask<String, Void, String> {
		    	
		    	String[] params;
		    	
		    	@Override
		    	protected String doInBackground(String... params) {
		    		try{
		        		
		        		this.params = params;
						//Log.e("providerString", providerString);
						
						//Log.e("actualProvider", actualProvider);
						
					    HttpClient httpclient = new DefaultHttpClient();  
					    HttpGet httpget = new HttpGet("https://www."+params[0]+"/myaccount/getbalance.php?username="+params[1].trim()+"&password="+params[2].trim());
			            // Add your data  
			            
			      
			            // Execute HTTP Post Request  
			            HttpResponse response = httpclient.execute(httpget);  
			            
			            byte buffer[] = new byte[1024] ;
						InputStream is = response.getEntity().getContent() ;
						int numBytes = is.read(buffer) ;
						is.close();
						
						 String entityContents = new String(buffer,0,numBytes) ;
					    
							

							
				            
						 return entityContents;   
						}      
			         catch (ClientProtocolException e) { 
			        	Log.e("Betamax" , e.getMessage());
			        	return "0.0"; 
			        } catch (IOException e) {  
			        	Log.e("Betamax" , e.getMessage());
			        	return "0.0"; 
			        }
			        
		    	
		    	
		    	
		 }
		    	
		    	@Override
		    	protected void onPostExecute(String result) {
		    	
		    		params[4] = result;
		    		try{
		    		AccountManager.this.dh.insert(params[0],params[1],params[2],params[3] , Double.parseDouble(params[4]));
		    		}
		    		catch(Exception e){AccountManager.this.dh.insert(params[0],params[1],params[2],params[3] , -1.0);}
		    		searchResults = refresh();
					lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));
		    	
		    	}
		    	
		 }
		 
		 public class edit_account extends AsyncTask<String, Void, String> {
		    	
		    	String[] params;
		    	
		    	@Override
		    	protected String doInBackground(String... params) {
		    		try{
		        		
		        		this.params = params;
						//Log.e("providerString", providerString);
						
						//Log.e("actualProvider", actualProvider);
						
					    HttpClient httpclient = new DefaultHttpClient();  
					    HttpGet httpget = new HttpGet("https://www."+params[1]+"/myaccount/getbalance.php?username="+params[2].trim()+"&password="+params[3].trim());
			            // Add your data  
			            
			      
			            // Execute HTTP Post Request  
			            HttpResponse response = httpclient.execute(httpget);  
			            
			            byte buffer[] = new byte[1024] ;
						InputStream is = response.getEntity().getContent() ;
						int numBytes = is.read(buffer) ;
						is.close();
						
						 String entityContents = new String(buffer,0,numBytes) ;
					    
							

							
				            
						 return entityContents;   
						}      
			         catch (ClientProtocolException e) { 
			        	Log.e("Betamax" , e.getMessage());
			        	return "0.0"; 
			        } catch (IOException e) {  
			        	Log.e("Betamax" , e.getMessage());
			        	return "0.0"; 
			        }
			        
		    	
		    	
		    	
		 }
		    	
		    	@Override
		    	protected void onPostExecute(String result) {
		    	
		    		params[5] = result;
		    		try{
		    		AccountManager.this.dh.update(Double.parseDouble(params[5]) , Integer.parseInt(params[0]) , params[1] , params[2] , params[3] , params[4] );
		    		}catch(Exception e){AccountManager.this.dh.update(-1.0 , Integer.parseInt(params[0]) , params[1] , params[2] , params[3] , params[4] );}
		    		searchResults = refresh();
					lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));
		    	
		    	}
		    	
		 }
		 
		 
		 
		 public class refresh_balance extends AsyncTask<String, Void, String> {
		    	
		    	String[] params;
		    	
		    	@Override
		    	protected String doInBackground(String... params) {
		    		try{
		        		
		        		this.params = params;
						//Log.e("providerString", providerString);
						
						//Log.e("actualProvider", actualProvider);
						
					    HttpClient httpclient = new DefaultHttpClient();  
					    HttpGet httpget = new HttpGet("https://www."+params[1]+"/myaccount/getbalance.php?username="+params[2].trim()+"&password="+params[3].trim());
			            // Add your data  
			            
			      
			            // Execute HTTP Post Request  
			            HttpResponse response = httpclient.execute(httpget);  
			            
			            byte buffer[] = new byte[1024] ;
						InputStream is = response.getEntity().getContent() ;
						int numBytes = is.read(buffer) ;
						is.close();
						
						 String entityContents = new String(buffer,0,numBytes) ;
					    
							

							
				            
						 return entityContents;   
						}      
			         catch (ClientProtocolException e) { 
			        	Log.e("Betamax" , e.getMessage());
			        	return "error"; 
			        } catch (IOException e) {  
			        	Log.e("Betamax" , e.getMessage());
			        	return "error"; 
			        }
			        
		    	
		    	
		    	
		 }
		    	
		    	@Override
		    	protected void onPostExecute(String result) {
		    	
		    		if(result.equalsIgnoreCase("error")){
		    			Toast.makeText(AccountManager.this, "Something went wrong. Please check your internet connection", Toast.LENGTH_LONG).show();
		    		}
		    		else{
		    		params[4] = result;
		    		try{
		    		AccountManager.this.dh.update( Double.parseDouble(params[4]),Integer.parseInt(params[0]));}
		    		catch(Exception e){AccountManager.this.dh.update( -1.0,Integer.parseInt(params[0]));}
		    		searchResults = refresh();
					lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));
		    		}
		    	}
		    	
		 }
		 
		 
		 @Override
		 public void onCreateContextMenu(ContextMenu menu, View v,
		     ContextMenuInfo menuInfo) {
		   if (v.getId()==R.id.list) {
		     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
		     Object o = lv1.getItemAtPosition(info.position);
	          SearchResults fullObject = (SearchResults)o;
	          //Toast.makeText(AccountManager.this, "Showing context menu for " + fullObject.getID(), Toast.LENGTH_SHORT).show();
		     String[] menuItems = {"Delete" , "Edit" , "Cancel"};
		     for (int i = 0; i<menuItems.length; i++) {
		       menu.add(Menu.NONE, i, i, menuItems[i]);
		     }
		   }
		 }
		 
		 
		 @Override
		 public boolean onContextItemSelected(MenuItem item) {
		   AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)item.getMenuInfo();
		   int menuItemIndex = item.getItemId();
		   String[] menuItems = {"Delete" , "Edit" , "Cancel"};
		   String menuItemName = menuItems[menuItemIndex];
		   Object o = lv1.getItemAtPosition(info.position);
	          final SearchResults fullObject = (SearchResults)o;

		   if(menuItemName.equalsIgnoreCase("Delete"))
		   {
			   
			   AlertDialog.Builder builder = new AlertDialog.Builder(AccountManager.this);
		          builder.setMessage("Are you sure you want to delete " + fullObject.getProvider() + " - " + fullObject.getUsername() + " account from Betamax Dialer Pro ?")
		                 .setCancelable(false)
		                 .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
		                     public void onClick(DialogInterface dialog, int id) {
		                          AccountManager.this.dh.deleteRow(fullObject.getID());
		                          searchResults = refresh();
		      					  lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));
		                     }
		                 })
		                 .setNegativeButton("No", new DialogInterface.OnClickListener() {
		                     public void onClick(DialogInterface dialog, int id) {
		                          dialog.cancel();
		                     }
		                 });
		          AlertDialog alert = builder.create();
		          alert.show();
			   
		   }
		   else if(menuItemName.equalsIgnoreCase("Edit"))
		   {
			   
			   AlertDialog.Builder builder;
				

				Context mContext = AccountManager.this;
				LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
				View layout = inflater.inflate(R.layout.edit_account,
				                               (ViewGroup) findViewById(R.id.edit_layout_root));
				final EditText provider = (EditText)layout.findViewById(R.id.edit_provider_disabled);
				provider.setText(fullObject.getProvider());
				final EditText username = (EditText)layout.findViewById(R.id.edit_acc_username);
				username.setText(fullObject.getUsername());
				final EditText password = (EditText)layout.findViewById(R.id.edit_acc_password);
				password.setText(fullObject.getPassword());
				final EditText accnumber = (EditText)layout.findViewById(R.id.edit_acc_number_edittext);
				accnumber.setText(fullObject.getAccNumber());
				Button edit_acc = (Button)layout.findViewById(R.id.edit_save_changes);

				builder = new AlertDialog.Builder(mContext);
				builder.setView(layout);
				final AlertDialog alertDialog = builder.create();
				alertDialog.show();
				
				//searchResults = refresh();
				//lv1.setAdapter(new AccountsBaseAdapter(AccountManager.this, searchResults));

				edit_acc.setOnClickListener(new OnClickListener(){

					public void onClick(View arg0) {
						int error = 0;
						String provider_string = provider.getText().toString();
						
						String username_string = username.getText().toString().trim();
						
						String password_string = password.getText().toString().trim();
						
						String acc_number_string = accnumber.getText().toString().trim();
						
						if(provider_string.equalsIgnoreCase("none")){
							Toast.makeText(getApplicationContext(), "Please choose a provider first.", Toast.LENGTH_LONG).show();
							error = 1;
						}
						else if(provider_string.equalsIgnoreCase("dialcheap.com") || provider_string.equalsIgnoreCase("megavoip.com")){
							Toast.makeText(getApplicationContext(), "Dialcheap and Megavoip are not currently supported. Please check back in the next update.", Toast.LENGTH_LONG).show();
							error = 1;
						}
						else if(username_string.equalsIgnoreCase("")){
							Toast.makeText(getApplicationContext(), "Please fill up the username field", Toast.LENGTH_LONG).show();
							error = 1;
						}
						else if(password_string.equalsIgnoreCase("")){
							Toast.makeText(getApplicationContext(), "Please fill_up the passworld field", Toast.LENGTH_LONG).show();
							error = 1;
						}
						else if(acc_number_string.equalsIgnoreCase("")){
							Toast.makeText(getApplicationContext(), "No Access Number provided. You will only be able to Callback from this account.", Toast.LENGTH_LONG).show();
						}
						
						if(error == 1)
							error = 0;
						else
						{
							Toast.makeText(getApplicationContext(), "Fetching account data. Please wait...", Toast.LENGTH_LONG).show();
							String[] params = {"" + fullObject.getID() ,provider_string , username_string, password_string, acc_number_string , ""};
							//Toast.makeText(getApplicationContext(), params[0] + "," + params[1] + "," + params[2] + "," + params[3], Toast.LENGTH_LONG).show();
							new edit_account().execute(params);
							alertDialog.cancel();
							
							
							
						}
							
					}
					
					
					
					
				});
				
			
			   
			   
		   }
		   return true;
		 }
		
		
	
	
	
	
}